package com.ruicar.afs.cloud.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.product.condition.ProductPlanCondition;
import com.ruicar.afs.cloud.product.entity.ProductPlanRate;
import com.ruicar.afs.cloud.product.service.ProductPlanRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author changyu.gui
 * @version 1.0
 * @date 2020/5/17 21:18
 */
@Slf4j
@RestController
@AllArgsConstructor
@Api("产品利率接口")
@RequestMapping("/productPlanRate")
public class ProductPlanRateController {
    @Autowired
    private ProductPlanRateService productPlanRateService;

    @PostMapping("/getProductPlanRateList")
    @ApiOperation(value = "查询产品利率数据")
    public IResponse<List<ProductPlanRate>> getProductPlanRateList(@RequestBody ProductPlanCondition planCondition) {
        List<ProductPlanRate> list = productPlanRateService.list(Wrappers.<ProductPlanRate>query().lambda().eq(ProductPlanRate::getProductPlanId, planCondition.getId()));
        return new IResponse<List<ProductPlanRate>>().setData(list);
    }

    @PostMapping("/saveProductPlanRate")
    @ApiOperation(value = "保存产品利率数据")
    @SysLog("保存产品利率数据")
    @Transactional
    public IResponse<Boolean> saveProductPlanRate(@RequestBody ProductPlanRate productPlanRate) {
        productPlanRateService.save(productPlanRate);
        return new IResponse<Boolean>().setMsg("保存产品利率数据成功");
    }

    @RequestMapping(value = "/deleteProductPlanRate/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除产品利率数据")
    @SysLog("删除产品利率数据")
    @Transactional
    public IResponse<Boolean> deleteProductPlanRate(@PathVariable String id) {
        productPlanRateService.removeById(id);
        return new IResponse<Boolean>().setMsg("删除产品利率数据成功");
    }

}
